package com.pkche.core.advanced.util.weixin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.codehaus.jettison.json.JSONObject;

/**
 * 新闻消息
 * @author yangqiang
 *
 */
public class NewsMessage extends BaseMessage {
	 // 图文消息个数，限制为10条以内  
    private int ArticleCount;  
    // 多条图文消息信息，默认第一个item为大图  
    private List<Article> Articles;  
  
    public int getArticleCount() {  
        return ArticleCount;  
    }  
  
    public void setArticleCount(int articleCount) {  
        ArticleCount = articleCount;  
    }  
  
    public List<Article> getArticles() {  
        return Articles;  
    }  
  
    public void setArticles(List<Article> articles) {  
        Articles = articles;  
    }
    
    /**
     * 转换成客服消息Json
     * @return
     */
    public String toRespJson(){
    	Map<String,Object> m = new HashMap<String, Object>();
		m.put("touser", getToUserName());
		m.put("msgtype", MessageUtil.RESP_MESSAGE_TYPE_NEWS);
		Map<String,Object> news = new HashMap<String, Object>();
		List<Map<String,String>> list = new ArrayList<Map<String,String>>();
		for(Article a : Articles){
			list.add(a.toRespMap());
		}
		news.put("articles", list);
		m.put("news", news);
		JSONObject json = new JSONObject(m);
    	return json.toString();
    }

}
